/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once


#include <基本类型.h>
#include <向量.h>
#include <vector>
#include <set>
#include <map>

#include "core/shader_tranform.h"
#include "core/shader_binding_ID.h"
#include "core/shader_curve.h"
//#include "core/vec_conversion.h"
//#include "core/mesh_container.h"
#include "core/结构数据.h"





struct S_内存分配 {
	std::set<uint64>           m_内存分配偏移;
	std::vector<S_GPU偏移大小> m_内存回收偏移;

	uint64             maxNum = 0;
	//uint8*             m_Data = nullptr;
};



typedef struct {
	uint32 光采样;
	uint32 反弹次数;
	uint32 采样次数;

	uint32 帧采样编号;
}S_RayRenderAttr;






typedef struct {
	S_CurvePoint*	point;
	uint32			count;
}S_曲线;



typedef enum {
	e_本体,
	e_引用,
}E_属性引用类型;


//=================== 物理可视数据 ======================



typedef struct {
	uint32* index;
	uint32	num;
}S_DomUnitIndex;


typedef struct {
	uvec3	m_分辨率;
	vec3	m_世界大小;
	vec3	m_域世界偏移;
	float32	m_单元大小;
}S_DomProp;
typedef struct {
	uvec4	m_分辨率;
	vec4	m_世界大小;
	vec4	m_域世界偏移;
	//float32	m_单元大小;
}S_域绘制属性;

typedef struct {
	S_DomProp	m_单元属性;
	
	//vec3	m_域世界大小;
	//vec3	m_域单元大小;
	//uvec3	m_分辨率;
	uint8* m_Mask;
}S_域区;


typedef struct {
	uint32 m_关联骨骼数量;
	uint32 m_骨骼内存偏移;
}S_骨骼属性;


struct S_体素 {
	uvec3					m_维度;
	std::vector<vec3>		m_坐标;
	std::vector<int8>		m_Mask;
	std::vector<uint32>		m_Index;
	std::vector<vec4>		m_法线;
	//std::vector<float32>	m_长度;
};





typedef enum : uint8 {
	e_事件传递_继续,
	e_事件传递_终止,
}E_事件是否传递;

typedef enum {
	e_键映射类型_键盘,
	e_键映射类型_鼠标,
	e_键映射类型_拖拽,
	e_键映射类型_双击,
}E_键位映射类型;

typedef E_事件是否传递(*fp_Widget快捷键事件)(struct C_Widget* self, uint8 状态);
typedef struct {
	E_键位映射类型		m_Type;
	fp_Widget快捷键事件	event;
	uint8				状态;
}S_键位映射;






typedef struct {
	vec2 coord;
	vec2 weights;
	vec2 normal;
}S_2D图元顶点;



struct S_边 {
	S_结构对象指针     polygon;
	std::vector<uvec2> edge;
};

struct S_面 {
	S_结构对象指针      polygon;
	std::vector<uint32> vertIndex;
	std::vector<uint32> edge;
	std::vector<uvec2>  uvLoopIndex;
	vec3                面中心;
	uint32              材质槽;
	uint32				ID;
};


#include "core/polygon.h"

//typedef struct {
//	S_面** ptr_userData;
//	uint32 count;
//}S_多边形元素;

//struct S_多边形元素 {
//	std::vector<uint32> 面索引;
//	//std::vector<uint32> 边索引;
//};

struct S_多边形 {
	std::vector<vec3> m_顶点;
	std::vector<vec3> m_法线;
	std::vector<vec2> m_UV;
	std::vector<uint32> m_UV索引;

	std::vector<S_边*>	m_边;
	std::vector<S_面*>	m_面;

	S_多边形元素Array*  m_元素组;
	
	uint8 m_UV层数量;

	std::map<std::wstring, S_Array*> m_点自定义属性;
	std::map<std::wstring, S_Array*> m_面自定义属性;
};



struct S_网格自定义属性 {
	E_值类型		m_Type;
	std::wstring*	m_Name;
	uint32			m_分布方式;
	S_多边形*		m_多边形;
	uint32			m_OffsetID;
	uint32			m_对应材质ID;
};





typedef enum : uint32 {
	t_空,

	t_网格 = DEF_ObType_Mesh,
	t_灯光 = DEF_ObType_Ligth,
	t_平行光 = DEF_ObType_Ligth_Parallel,
	t_点光源 = DEF_ObType_Ligth_Point,
	t_区域光 = DEF_ObType_Ligth_Area,
	t_聚光灯 = DEF_ObType_Ligth_Spot,

	t_区域光_方形 = DEF_ObType_Ligth_RectArea,
	t_区域光_圆形 = DEF_ObType_Ligth_CircleArea,

	t_实例,
	t_线,
	t_线段,
	t_粒子,

	t_多边形,
	t_摄像机,
	t_骨骼,
	t_骨架,
	
	t_物体包,
	t_包,
	t_虚拟体,

	

	t_GL立即模式,
}E_物体类型;









struct S_文档文本 {
	std::wstring			m_Text;
	std::vector<S_文档文本> m_字文本块;

	std::vector<std::wstring>				m_文本块;
	std::vector< std::vector<S_RGBA8UI>>	m_Color;
	bool									m_子块折叠;
};




#define _S_边Array			\
typedef struct {			\
	S_边**	ptr_userData;	\
	uint32	count;			\
}S_边Array;

_S_边Array;


#define _S_MaterialArray	      \
typedef struct {			      \
	struct S_材质** ptr_userData; \
	uint32   count;			      \
}S_MaterialArray;

_S_MaterialArray;



#define _S_MeshArray	          \
typedef struct {			      \
	struct S_Mesh** ptr_userData; \
	uint32   count;			      \
}S_MeshArray;

_S_MeshArray;



#define _S_OBArray	              \
typedef struct {			      \
	struct S_物体** ptr_userData; \
	uint32   count;			      \
}S_OBArray;

_S_OBArray;



#define _S_ElementSelect       \
typedef struct {		       \
	S_UI32Array*   Index;      \
	void*          Element;	   \
	E_值类型       Type;	   \
}S_ElementSelect;

_S_ElementSelect;



#define _S_ElementSelectArray       \
typedef struct {		            \
	S_ElementSelect** elementArray; \
	uint32           count;	        \
}S_ElementSelectArray;

_S_ElementSelectArray;





struct S_纹理添加列队 {
	std::string     m_加载路径;
	struct S_纹理*  m_纹理对象;
	struct S_Scene* m_Scene;
	void*			m_内存数据;
	uvec3           m_新大小;
};

